package com.java.dormitorymanager.mvc.view;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

/**
 * @program: DormitoryManager
 * @description: 修改宿舍信息界面
 * @author: ShuangChenYue
 * @create: 2021-05-18 15:49
 **/

@WebServlet(value = "/ViewUpdateDormInfo")
public class ViewUpdateDormInfoServlet extends HttpServlet
{
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        doPost(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException
    {
        System.out.println("点击修改按钮后来到此页面");
        req.setCharacterEncoding("utf-8");
        resp.setContentType("text/html");
        resp.setCharacterEncoding("utf-8");
        PrintWriter out = resp.getWriter();

        out.println("<!DOCTYPE html>");
        out.println("<html lang=\"en\">");
        out.println("<head>");
        out.println("<meta charset=\"UTF-8\">");
        out.println("<title>修改宿舍信息</title>");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-dorm/updateDormInfo.css\">");
        out.println("<link rel=\"stylesheet\" type=\"text/css\" href=\"http://localhost:8080/DormitoryManager/css/css-other/doIcon.css\">");
        out.println("</head>");
        out.println("<body>");
        out.println("<div id=\"divTitle\">");
        out.println("<h1 id=\"h01\">Manage Dorm</h1>");
        out.println("</div>");
        out.println("<div id=\"registerBox\">");
        out.println("<h1>Update Info</h1>");
        String dornum = (String) req.getAttribute("dornum");
        out.println("<form id=\"registerForm\" action=\"/DormitoryManager/mvc/afterUpdateDormInfo.do?metaDornum="+dornum+"\" method=\"post\">");
        out.println("<table id=\"registerTable\">");

        out.println("<tr>");
        int id = (int) req.getAttribute("id");
        out.println("<td id=\"tdId\" colspan=\"2\"><i id=\"IdIcon\" class=\"iconfontU\">&#xe64d;</i><input id=\"inputId\" type=\"text\" name=\"id\" placeholder=\"宿舍ID\" value="+id+" readonly=\"readonly\" style=\"color:gray\"></td>");
        out.println("</tr>");

        out.println("<tr>");
        out.println("<td id=\"tdDornum\" colspan=\"2\"><i id=\"dornumIcon\" class=\"iconfontU\">&#xe615;</i><input id=\"inputDornum\" type=\"text\" name=\"dornum\" placeholder=\"宿舍编号\" value="+dornum+"></td>");
        out.println("</tr>");
        out.println("<tr>");
        out.println("<td id=\"tdSubmit\" colspan=\"2\"><input id=\"inputSubmit\" type=\"submit\" value=\"Update\" title=\"点击修改\"></td>");
        out.println("</tr>");
        out.println("</table>");
        out.println("</form>");
        out.println("</div>");
        out.println("</body>");
        out.println("</html>");
        out.flush();
        out.close();
    }
}
